<template>
  <view class="content-analyse">
    <view class="header">
      <view class="top">
        <up-row>
          <up-col span="6">
            <view class="header-left"> {{ t("common.powerAnalysis") }} </view>
          </up-col>
          <up-col span="6">
            <view class="header-right" @click="handleShowTime">
              <image class="img" src="/static/power-icon.png" mode="" />
              <text> {{ getTimeJson() }}</text>
            </view>
          </up-col>
        </up-row>
      </view>
    </view>

    <template v-if="Object.keys(chartOption).length !== 0">
      <EChartsWrapper :option="chartOption" />
    </template>
    <template v-else>
      <up-empty icon="/static/no-empty.png" :text="t('common.empty')">
      </up-empty>
    </template>
  </view>

  <dateTimePicker
    :timeMode="'date'"
    :timeVal="timeVal"
    :showTimeVal="showTimeVal"
    @handleTimeClose="showTimeVal = false"
    @handleTimeConfirm="handleTimeConfirm"
  />
</template>

<script setup>
import { ref, defineExpose, watch } from "vue";
import { timestampToDate } from "@/utils/utils.js";
const timeVal = ref(Date.now());
const showTimeVal = ref(false);
import { useI18n } from "vue-i18n";
const { t } = useI18n();

const props = defineProps({
  powerChart: {
    type: Object,
    detail: {},
  },
});
// 定义图表配置项

const chartOption = ref(props.powerChart);
watch(
  () => props.powerChart,
  (val) => {
    chartOption.value = val;
  }
);

const emit = defineEmits(["handleTime"]);
const handleShowTime = () => {
  showTimeVal.value = true;
};

const getTimeJson = () => {
  return timestampToDate(timeVal.value);
};
defineExpose({
  getTimeJson,
});
const handleTimeConfirm = (params) => {
  timeVal.value = params;
  emit("handleTime");
};
// 处理确认事件
const handleConfirm = (value) => {
  console.log("确认选择的日期时间:", value);
};

// 处理取消事件
const handleCancel = () => {
  console.log("取消选择");
};
</script>

<style lang="scss" scoped>
.content-analyse {
  width: 100%;
  border-radius: 16rpx;
  background: #132034;
  padding: 32rpx 10rpx;
  box-sizing: border-box;

  .header {
    padding: 0rpx 39rpx;
    box-sizing: border-box;
    width: 100%;

    .top {
      width: 100%;
      position: relative;
    }

    .header-left {
      font-family: PingFangSC;
      font-size: 32rpx;
      font-weight: normal;
      color: #eeeeee;
    }

    .header-right {
      width: 200rpx;
      height: 60rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      background-color: #08121e;
      border-radius: 10rpx;
      float: right;

      .img {
        width: 20rpx;
        height: 20rpx;
        margin-right: 14rpx;
      }

      text {
        font-family: Alibaba PuHuiTi 3;
        font-size: 22rpx;
        font-weight: normal;
        font-variation-settings: "opsz" auto;
        color: #ffffff;
      }
    }

    :deep(.u-subsection) {
      width: 270rpx;
    }

    :deep(.u-subsection--button__bar) {
      width: 90rpx !important;
      background: #64b7f6;
    }

    .top::after {
      content: "";
      position: absolute;
      left: -49rpx;
      top: 50%;
      transform: translateY(-50%);
      width: 8rpx;
      height: 32rpx;
      border-radius: 0px 8rpx 8rpx 0rpx;
      opacity: 1;
      background: #64b7f6;
    }
  }

  .noData {
    width: 100%;
    text-align: center;
    font-size: 28rpx;
  }
}
</style>
